﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using TTSIDAL;
using TTSModel;

namespace TTSDAL
{
    public class Unit : BaseRepository<UnitInfo>, IUnit
    {
        #region 静态变量定义
        private const string PARM_UNIT_SN = "@SN";
        private const string PARM_UNIT_TCODE = "@Tcode";
        private const string PARM_UNIT_ISLEAF = "@IsLeaf";
        private const string PARM_UNIT_ISROOT = "@IsRoot";
        #endregion

        #region 数据检索部分
        public IList<UnitInfo> LoadEntities()
        {
            return null;
        }

        public UnitInfo LoadEntity<T1>(T1 sn)
        {
            SqlParameter parm = GetParameter();
            parm.Value = sn;
            return ExcuteSqlToGetEntity("Unit_selectbySN", parm);
        }
        #endregion

        #region 重写基类方法
        public override UnitInfo GetEntityRecord(SqlDataReader rdr)
        {
            UnitInfo entity = new UnitInfo()
            {
                SN = rdr.GetValue(0).ToString(),
                Tcode = rdr.GetValue(1).ToString(),
                IsLeaf = rdr.GetBoolean(2),
                IsRoot=rdr.GetBoolean(3)
            };
            return entity;
        }

        public override UnitInfo GetEntityRecord()
        {
            UnitInfo entity = new UnitInfo();
            return entity;
        }

        public override string GetInsertsp()
        {
            return "Unit_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter parm = new SqlParameter(PARM_UNIT_SN, SqlDbType.NVarChar, 50);
            return parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter(PARM_UNIT_SN,SqlDbType.NVarChar,50),
                new SqlParameter(PARM_UNIT_TCODE,SqlDbType.NChar,8),
                new SqlParameter(PARM_UNIT_ISLEAF,SqlDbType.Bit,1),
                new SqlParameter(PARM_UNIT_ISROOT,SqlDbType.Bit,1),
            };
            return parms;
        }

        public override void SetParameters(UnitInfo Entity, params SqlParameter[] Parms)
        {
            Parms[0].Value = Entity.SN;
            Parms[1].Value = Entity.Tcode;
            Parms[2].Value = Entity.IsLeaf;
            Parms[3].Value = Entity.IsRoot;
        }
        #endregion
    }
}
